package program

import "gorm.io/gorm"

type MiniProgram struct {
	gorm.Model        // gorm自带ID, craeteAt, updateAt, deleteAt
	ProgramId  string `json:"programId" gorm:"column:program_id;size:255;comment:'小程序id'"`
	Mode       string `json:"mode" gorm:"column:mode;size:255;not null;comment:'小程序/js type：dev、preview、prod'"`
	FileName   string `json:"fileName" gorm:"column:file_name;size:255;not null;comment:'文件名'"`
	FileType   string `json:"fileType" gorm:"column:file_type;size:255;not null;comment:'文件类型：program小程序；js js包'"`
	FileId     string `json:"fileId" gorm:"column:file_id;size:255;not null;index:idx_fileId,unique;comment:'filetype+mode+version 哈希值'"`
	Version    string `json:"version" gorm:"column:version;size:255;not null;comment:'版本'"`
}

func (MiniProgram) TableName() string {
	return "tb_mini_program"
}

type ModeType int
type FileType int

const (
	Dev     ModeType = 0
	Preview ModeType = 1
	Prod    ModeType = 2

	Program FileType = 0
	Js      FileType = 1
)

func (c ModeType) String() string {
	switch c {
	case Dev:
		return "dev"
	case Preview:
		return "preview"
	case Prod:
		return "prod"
	}
	return ""
}

func (c FileType) String() string {
	switch c {
	case Program:
		return "program"
	case Js:
		return "js"
	}
	return ""
}
